package androidx.activity;

import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import androidx.core.app.e;
import androidx.lifecycle.e;
import androidx.lifecycle.f;
import androidx.lifecycle.h;
import androidx.lifecycle.i;
import androidx.lifecycle.p;
import androidx.lifecycle.u;
import androidx.lifecycle.v;
import androidx.savedstate.SavedStateRegistry;

public class ComponentActivity extends e implements h, v, androidx.savedstate.b, c {

    /* renamed from: c  reason: collision with root package name */
    private final i f59c = new i(this);

    /* renamed from: d  reason: collision with root package name */
    private final androidx.savedstate.a f60d = androidx.savedstate.a.a(this);
    private u e;
    private final OnBackPressedDispatcher f = new OnBackPressedDispatcher(new a());
    private int g;

    class a implements Runnable {
        a() {
        }

        public void run() {
            ComponentActivity.super.onBackPressed();
        }
    }

    static final class b {

        /* renamed from: a  reason: collision with root package name */
        u f64a;

        b() {
        }
    }

    public ComponentActivity() {
        if (getLifecycle() != null) {
            if (Build.VERSION.SDK_INT >= 19) {
                getLifecycle().a(new f() {
                    public void d(h hVar, e.a aVar) {
                        if (aVar == e.a.ON_STOP) {
                            Window window = ComponentActivity.this.getWindow();
                            View peekDecorView = window != null ? window.peekDecorView() : null;
                            if (peekDecorView != null) {
                                peekDecorView.cancelPendingInputEvents();
                            }
                        }
                    }
                });
            }
            getLifecycle().a(new f() {
                public void d(h hVar, e.a aVar) {
                    if (aVar == e.a.ON_DESTROY && !ComponentActivity.this.isChangingConfigurations()) {
                        ComponentActivity.this.getViewModelStore().a();
                    }
                }
            });
            int i = Build.VERSION.SDK_INT;
            if (19 <= i && i <= 23) {
                getLifecycle().a(new ImmLeaksCleaner(this));
                return;
            }
            return;
        }
        throw new IllegalStateException("getLifecycle() returned null in ComponentActivity's constructor. Please make sure you are lazily constructing your Lifecycle in the first call to getLifecycle() rather than relying on field initialization.");
    }

    public final OnBackPressedDispatcher b() {
        return this.f;
    }

    public androidx.lifecycle.e getLifecycle() {
        return this.f59c;
    }

    public final SavedStateRegistry getSavedStateRegistry() {
        return this.f60d.b();
    }

    public u getViewModelStore() {
        if (getApplication() != null) {
            if (this.e == null) {
                b bVar = (b) getLastNonConfigurationInstance();
                if (bVar != null) {
                    this.e = bVar.f64a;
                }
                if (this.e == null) {
                    this.e = new u();
                }
            }
            return this.e;
        }
        throw new IllegalStateException("Your activity is not yet attached to the Application instance. You can't request ViewModel before onCreate call.");
    }

    @Deprecated
    public Object i() {
        return null;
    }

    public void onBackPressed() {
        this.f.c();
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f60d.c(bundle);
        p.f(this);
        int i = this.g;
        if (i != 0) {
            setContentView(i);
        }
    }

    public final Object onRetainNonConfigurationInstance() {
        b bVar;
        Object i = i();
        u uVar = this.e;
        if (uVar == null && (bVar = (b) getLastNonConfigurationInstance()) != null) {
            uVar = bVar.f64a;
        }
        if (uVar == null && i == null) {
            return null;
        }
        b bVar2 = new b();
        bVar2.f64a = uVar;
        return bVar2;
    }

    /* access modifiers changed from: protected */
    public void onSaveInstanceState(Bundle bundle) {
        androidx.lifecycle.e lifecycle = getLifecycle();
        if (lifecycle instanceof i) {
            ((i) lifecycle).p(e.b.CREATED);
        }
        super.onSaveInstanceState(bundle);
        this.f60d.d(bundle);
    }
}
